package ${package.Controller};
<#assign tableName = "${table.controllerName}"?replace("Controller","")>
<#assign uncapServiceName = "${table.serviceName}"?uncap_first>
<#assign uncapQueryService = "${tableName}QueryService"?uncap_first>
<#assign uncapTableName = "${tableName}"?uncap_first>

import com.smedi.ismedi.web.starter.common.PaginationData;
import lombok.AllArgsConstructor;
import com.smedi.ismedi.authority.starter.common.ResponseData;
import ${package.Parent}.core.application.command.Add${tableName}Command;
import ${package.Parent}.core.application.query.${tableName}QueryService;
import ${package.Parent}.core.application.service.${tableName}ApplicationService;
import ${package.Parent}.core.port.adapter.convert.AdapterConverter;
import org.springframework.web.bind.annotation.RestController;
import ${package.Parent}.api.dto.request.*;
import ${package.Parent}.core.domain.aggregatemodel.*;
import ${package.Parent}.api.dto.response.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import ${package.Parent}.core.application.command.*;
import ${package.Parent}.api.feign.Remote${tableName}FeignApi;
import java.util.List;

/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 * @author ${author}
 * @since ${date}
 */

@AllArgsConstructor
@RestController
public class ${table.controllerName} implements Remote${tableName}FeignApi{

    private AdapterConverter adapterConverter;

    private ${table.serviceName}  ${uncapServiceName};

    private ${tableName}QueryService  ${uncapQueryService};
    /**
     * 新增
     */
    @Override
    public ResponseData<${tableName}Response> add${tableName}(Add${tableName}Request add${tableName}Requset){
        Add${tableName}Command add${tableName}Command = adapterConverter.add${tableName}RequestToAdd${tableName}Command(add${tableName}Requset);
        ${tableName} add${tableName} = ${uncapServiceName}.add${tableName}(add${tableName}Command);
        return new ResponseData<>().success(adapterConverter.${tableName}To${tableName}Response(add${tableName}));
    }

    /**
     * 删除
     */
    @Override
    public ResponseData<Boolean> del${tableName}(Del${tableName}Request del${tableName}Request){
        Del${tableName}Command del${tableName}Command = adapterConverter.del${tableName}RequestToDel${tableName}Command(del${tableName}Request);
        ${uncapServiceName}.del${tableName}(del${tableName}Command);
        return new ResponseData<>().success(true);
    }

    /**
     * 修改
     */
    @Override
    public ResponseData<${tableName}Response> update${tableName}(Update${tableName}Request update${tableName}Request){
        Update${tableName}Command update${tableName}Command = adapterConverter.update${tableName}RequestToUpdate${tableName}Command(update${tableName}Request);
        ${tableName} update${tableName} = ${uncapServiceName}.update${tableName}(update${tableName}Command);
        return new ResponseData<>().success(adapterConverter.${tableName}To${tableName}Response(update${tableName}));
    }

    /**
     * 分页查询
     */
    @Override
    public ResponseData<PaginationData<${tableName}Response>> query${tableName}ByPage(Query${tableName}PageRequest query${tableName}PageRequest){
        Query${tableName}PageCommand query${tableName}PageCommand = adapterConverter.query${tableName}PageRequestToQuery${tableName}PageCommand(query${tableName}PageRequest);
        Page<${tableName}> query${tableName}Page = ${uncapQueryService}.query${tableName}Page(query${tableName}PageCommand);
        return new ResponseData<>().success(adapterConverter.${tableName}PageTo${tableName}ResponsePage(query${tableName}Page));
    }
    /**
     * 单个查询
     */
    @Override
    public ResponseData<${tableName}Response> query${tableName}ByOne(Query${tableName}ByOneRequest query${tableName}ByOneRequest){
        Query${tableName}ByOneCommand query${tableName}ByOneCommand = adapterConverter.query${tableName}ByOneRequestToQuery${tableName}ByOneCommand(query${tableName}ByOneRequest);
        ${tableName} ${uncapTableName} = ${uncapQueryService}.query${tableName}ByOne(query${tableName}ByOneCommand);
        return new ResponseData<>().success(adapterConverter.${tableName}To${tableName}Response(${uncapTableName}));
    }

    /**
     * 列表查询
     */
    @Override
    public ResponseData<List<${tableName}Response>> query${tableName}List(Query${tableName}ListRequest query${tableName}ListRequest){
        Query${tableName}ListCommand query${tableName}ListCommand = adapterConverter.query${tableName}ListRequestToQuery${tableName}ListCommand(query${tableName}ListRequest);
        List<${tableName}> ${uncapTableName}List = ${uncapQueryService}.query${tableName}List(query${tableName}ListCommand);
        return new ResponseData<>().success(adapterConverter.${tableName}ListTo${tableName}ResponseList(${uncapTableName}List));
    }
}

